package com.cigs.wcs00a.business.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.cigs.wcs00a.business.entity.TWcsTaskLog;
import com.cigs.wcs00a.business.params.TWcsTaksLogParam;
import com.cigs.wcs00a.business.params.WcsTaskLogQueryParam;
import com.cigs.wcs00a.business.service.ITWcsTaskLogService;
import com.cigs.wcs00a.common.param.IdParam;
import com.cigs.wcs00a.common.vo.R;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * wcs 任务信息日志表 前端控制器
 * </p>
 *
 * @author caixiang
 * @since 2021-10-09
 */
@RestController
@RequestMapping("/business/t-wcs-task-log")
public class TWcsTaskLogController {
    @Autowired
    ITWcsTaskLogService service;

    /**
     * 输入关键字后 点击查询按钮 查询
     * */
    @PostMapping(value = "findAll")
    @ApiOperation(value="查询所有 wms传递给wcs的 任务", notes="查询所有 wms传递给wcs的 任务")
    private R<IPage<TWcsTaskLog>> findAll(@RequestBody WcsTaskLogQueryParam wcsTaskQueryParam) {
        IPage<TWcsTaskLog> all = service.findAll(wcsTaskQueryParam);
        return R.ok(all);
    }

    /**
     * 输入关键字后 点击查询按钮 查询
     * */
    @PostMapping(value = "create")
    @ApiOperation(value="用于记录wms 发给wcs 的log")
    private R<Boolean> create(@RequestBody TWcsTaksLogParam tWcsTaksLogParam) {
        TWcsTaskLog tWcsTask = new TWcsTaskLog();
        BeanUtils.copyProperties(tWcsTaksLogParam, tWcsTask);
        return R.ok(service.create(tWcsTask));
    }

    /**
     * 逻辑删除
     * */
    @PostMapping(value = "delete")
    @ApiOperation(value="逻辑删除这条任务，依据id")
    private R<Boolean> delete(@RequestBody IdParam idParam) {
        TWcsTaskLog tWcsTask = new TWcsTaskLog();
        tWcsTask.setId(idParam.getId());
        tWcsTask.setValid(0);
        Boolean update = service.updateById(tWcsTask);
        if(update){
            return R.ok(update).msg("成功");
        }else {
            return R.ok(update).msg("失败");
        }

    }

    /**
     * 逻辑删除
     * */
    @PostMapping(value = "findById")
    @ApiOperation(value="查找数据，依据id")
    private R<TWcsTaskLog> findById(@RequestBody IdParam idParam) {
        return R.ok(service.findById(idParam));
    }
}
